//
//  MainViewController.m
//  UI08_3_页面间传值(协议传值)
//
//  Created by Scott on 15/4/29.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "MainViewController.h"
#import "SecondViewController.h"

#warning 协议传值: 4. 签订协议
@interface MainViewController () <SecondViewControllerDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"登录系统";
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 100, 300, 40);
    [button setTitle:@"输入用户名" forState:UIControlStateNormal];
    button.layer.borderWidth = 1.f;
    button.layer.cornerRadius = 10.f;
    [self.view addSubview:button];
    button.tag = 100;
    
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)buttonClicked:(UIButton *)button
{
    SecondViewController *second = [[SecondViewController alloc] init];
    
#warning 协议传值: 5. 设置第二页面的代理人
    second.delegate = self;
    [self.navigationController pushViewController:second animated:YES
     ];
    [second release];
}

#warning 协议传值: 6. 实现协议方法
- (void)passValue:(NSString *)string
{
    UIButton *button = (UIButton *)[self.view viewWithTag:100];
    [button setTitle:string forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
